//
//  Test.m
//  testapp
//
//  Created by Heng Yue on 2019/11/6.
//  Copyright © 2019 Heng Yue. All rights reserved.
//

#import "Test.h"
#import "LoginVC.h"
#import "ViewController.h"
#import "ListViewController.h"
@interface Test ()<UITableViewDelegate,UITableViewDataSource,UIViewControllerPreviewingDelegate>
@property(nonatomic,strong) UITableView *tableView;
@end

@implementation Test

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    [self.navigationController setNavigationBarHidden:YES];
    self.view.backgroundColor=[UIColor whiteColor];
    self.tableView=[[UITableView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.tableView];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
   
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text=[NSString stringWithFormat:@"index == %ld",indexPath.row];
   [self registerForPreviewingWithDelegate:(id)self sourceView:cell];
    return cell;
}
-(NSArray*)previewActionItems{
       UIPreviewAction * action1 = [UIPreviewAction actionWithTitle:@"收藏" style:1 handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
            NSLog(@"收藏");
    }];

     UIPreviewAction * action2 = [UIPreviewAction actionWithTitle:@"喜欢" style:0 handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
            NSLog(@"喜欢");

     }];
     NSArray *items = @[action1,action2];
     return items;
}
#pragma mark - peek的代理方法，轻按即可触发弹出vc
- (UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
    //通过[previewingContext sourceView]拿到对应的cell的数据；
    NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:location];
    // 用于显示预览的vc
    ListViewController *listVc = [[ListViewController alloc] init];
    // 演示的是传入一个字符串 , 实际可能是你需要的model
    listVc.str = [NSString stringWithFormat:@"index == %ld",indexPath.row];
    return listVc;
}
#pragma mark -  pop的代理方法，在此处可对将要进入的vc进行处理
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
{
    [self showViewController:viewControllerToCommit sender:self];
}


//-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    LoginVC *vc=[[LoginVC alloc] init];
//    UINavigationController *root=(UINavigationController*)[UIApplication sharedApplication].keyWindow.rootViewController;
//    vc.modalPresentationStyle=UIModalPresentationFullScreen;
//    [root presentViewController:vc animated:YES completion:nil];
    
//}
-(void)dealloc{
    NSLog(@"%@--%@",[self class],NSStringFromSelector(_cmd));
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
